<?php
/**
 * SdecoController
 */
namespace App\Http\ControllersAdmin;

use App\Service\SdecoService;
use App\Validation\SlistSearchValidation;
use App\Validation\DeleteValidation;
use App\Validation\BatchValidation;

class SdecoController extends BaseController
{
	const MIGRATE_TRUE = 1;		//入库标识：是
	const MIGRATE_FALSE = 0;	//入库标识：否
	
	/**
	 * [indexAction 列表]
	 * @return [type] [description]
	 */
	public function indexAction()
	{
		$this->getUser();
		$raw = $this->validation(new SlistSearchValidation, $this->request->getJsonRawBody());
		$raw->is_migrate = self::MIGRATE_FALSE;
		$data = SdecoService::getList($raw);	
		$count = SdecoService::getList($raw, TRUE);

		$assign = [
			'total' => $count,
			'list'  => $data
		];
		return $this->echoJson($assign);
	}

	/**
	 * [detailAction 详情]
	 * @return [type] [description]
	 */
	public function detailAction()
	{
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = SdecoService::getInfo($raw->id);
		return $this->echoJson($data);
	}

	/**
	 * [deleteAction 删除]
	 * @return [type] [description]
	 */
	public function deleteAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = SdecoService::delete($raw->id);
		return $this->echoJson('ok');
	}

	/**
	 * [foreverAction 彻底删除]
	 * @return [type] [description]
	 */
	public function foreverAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = SdecoService::forever($raw->id);
		return $this->echoJson('ok');
	}

	/**
	 * [migrateAction 入库]
	 * @return [type] [description]
	 */
	public function migrateAction()
	{
		$raw = $this->validation(new BatchValidation, $this->request->getJsonRawBody());
		SdecoService::batchMigrate($raw->id);
		// $raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		// SdecoService::migrate($raw->id);
		return $this->echoJson("ok");
	}
}